import Vue from 'vue'
import App from './App.vue'
import router from './router'
import session from './assets/session'

Vue.config.productionTip = false

Vue.prototype.$session = session;

import {
  Button,
  Toast,
  Field,
  Cell,
  Dialog,
} from "vant";
Vue.use(Button)
  .use(Toast)
  .use(Field)
  .use(Dialog)
  .use(Cell)

  // 路由守卫
// 全局拦截，查看登陆状态，没有登陆 => login
router.beforeEach((to, from, next) => {
  if (
      to.name === "login" ||
      to.name === "register"
  ) {
      // 当前跳转到login => next
      next();
  } else {
      // console.log(store);
      let token = session.get().token;
      if (token) {
          next();
      } else {
          next("login");
      }
  }
});

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
